package com.ymttest.business.service;

import com.ymatou.iapi.productmanager.parameter.AddMicroProductBean;
import com.ymatou.iapi.productmanager.parameter.MicroProductBean;
import com.ymatou.iapi.productmanager.parameter.WeChatProductModel;
import com.ymatou.iapi.productmanager.parameter.product.*;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.Logger;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.annotation.product.IntergratedProductMapper;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class AddProductCallServiceV2 {
    private static  IntergratedProductMapper ipm = SqlMapperFactory
            .getIntergratedProductMapper();

    /**
     * 验证发布商品
     * @param productId
     * @param addpro
     */
    public static void checkAddProduct(String productId, AddSellerProductRequest addpro) throws Exception {
        //验证Ymt_Products商品信息
        Map pmap = ipm.selectProductByProdId(productId);
        Logger.debug(pmap);
        Logger.verifyEquals(addpro.getSellerId(),Integer.parseInt(pmap.get("iUserId").toString()),"验证SellerId");
        Logger.verifyEquals(addpro.getSellerName(), pmap.get("SellerLoginId").toString(), "验证sellerName");
        ProductSaveModel prodSaveModel = addpro.getProduct();
        Logger.verifyEquals(prodSaveModel.getProductName(),pmap.get("sProduct").toString(),"验证productName");
        Logger.verifyEquals(prodSaveModel.getSpuId(),Integer.parseInt(pmap.get("iSpuId").toString()),"验证spuid");
        Logger.verifyEquals(prodSaveModel.getSecondCategoryId(),Integer.parseInt(pmap.get("iCategoryId").toString()),"验证二级类目编号");
        Logger.verifyEquals(prodSaveModel.getBrandId(),Integer.parseInt(pmap.get("iBrandId").toString()),"验证品牌编号");
        if(prodSaveModel.getRecomReason()!=null) {
        	Logger.verifyEquals(prodSaveModel.getRecomReason(),pmap.get("RecomReason").toString(),"验证recomReason");
        }
//        if(prodSaveModel.getProductTags()!=null) {
//        	Logger.verifyEquals(prodSaveModel.getProductTags(),pmap.get("productTags").toString(),"验证productTags");
//        }
        AssertService.assertTime(YMTDateUtil.getDate(), (Date)pmap.get("dAddTime"), 120,"验证商品发布时间");
        AssertService.assertTime(YMTDateUtil.getDate(), (Date)pmap.get("dLastUpdate"), 120,"验证商品最后更新时间");

        Logger.verifyEquals(prodSaveModel.getProductPicList().get(0),pmap.get("sPicUrl").toString(),"验证商品主图（首图）");
        Logger.verifyEquals(0,Integer.parseInt(pmap.get("iAction").toString()),"验证action");
        Logger.verifyEquals(prodSaveModel.getCatalogType(),Integer.parseInt(pmap.get("iCatalogType").toString()),"验证商品备货方式");
        Logger.verifyEquals(prodSaveModel.getCatalogStatus(),Integer.parseInt(pmap.get("iCatalogStatus").toString()),"验证商品物流类型");
        Logger.verifyEquals(prodSaveModel.getThirdCategoryId(),Integer.parseInt(pmap.get("iThirdCategoryId").toString()),"验证商品三级类目编号");
        Logger.verifyEquals(prodSaveModel.getTariffType(),Integer.parseInt(pmap.get("iTariffType").toString()),"验证商品交税方式");
        Logger.verifyEquals(prodSaveModel.isNoticeRisk(),pmap.get("bNoticeRisk"),"验证商品砍单风险");
        Logger.verifyEquals(false,pmap.get("isNew"),"验证是否新品");
        Logger.verifyEquals(prodSaveModel.getBondedArea(),Integer.parseInt(pmap.get("iBondedArea").toString()),"验证商品保税区");
        Logger.verifyEquals(prodSaveModel.getMultiLogistics(),Integer.parseInt(pmap.get("iMultiLogistics").toString()),"验证多物流类型");
        Logger.verifyEquals(prodSaveModel.getFlightBalance(),Double.valueOf(pmap.get("dFlightBalance").toString()),"验证多物流差价");
        Logger.verifyEquals(prodSaveModel.getWeightUnit(),Integer.parseInt(pmap.get("WeightUnit").toString()),"验证多商品重量");
        Logger.verifyEquals(prodSaveModel.getProductCode(),pmap.get("sProductCode").toString(),"验证商品备案号");
        Logger.verifyEquals(prodSaveModel.getRemark(),pmap.get("Remark").toString(),"验证商品描述");
        Logger.verifyEquals(0,Integer.parseInt(pmap.get("GiftType").toString()),"验证礼包类型");
        Logger.verifyEquals(prodSaveModel.getPackageDeliveryType(),Integer.parseInt(pmap.get("PackageDeliveryType").toString()),"验证PackageDeliveryType");
        Logger.debug(addpro.getSellerId());
        Logger.debug(Integer.parseInt(EnvSetup.getData("globalSellerId")));
        if(addpro.getSellerId()==Integer.parseInt(EnvSetup.getData("globalSellerId"))){
            Logger.verifyEquals(2,Integer.parseInt(pmap.get("ProductType").toString()),"验证商品类型");
            Logger.verifyEquals(addpro.getProduct().isAutoRefresh(),pmap.get("bAutoRefresh"),"验证商品是否自动延期");
        }else if(addpro.getProduct().getLiveRoomId()!=0){
            Logger.verifyEquals(4,Integer.parseInt(pmap.get("ProductType").toString()),"验证商品类型");
            Logger.verifyEquals(false,pmap.get("bAutoRefresh"),"验证商品是否自动延期");
        } else{
            Logger.verifyEquals(0,Integer.parseInt(pmap.get("ProductType").toString()),"验证商品类型");
            Logger.verifyEquals(addpro.getProduct().isAutoRefresh(),pmap.get("bAutoRefresh"),"验证商品是否自动延期");

        }

        Date reqStartDate = YMTDateUtil.getDate(addpro
                .getProduct().getValidStart(), YMTDateUtil.YMDHMS);
        Date reqEndDate = YMTDateUtil.getDate(addpro
                .getProduct().getValidEnd(), YMTDateUtil.YMDHMS);
        Date startDateInSql = (Date) pmap.get("validStart");
        Date endDateInSql = (Date) pmap.get("validEnd");

        //验证商品开始的有效期
        AssertService.assertTime(reqStartDate, startDateInSql, 120,"验证validstart");
        //验证商品结束的有效期
//        AssertService.assertTime(reqEndDate, endDateInSql, 120,"验证validend");
        //验证商品的发布时间
        AssertService.assertTime(YMTDateUtil.getDate(),(Date) pmap.get("dAddTime"),120,"验证商品的发布时间");

        //验证Ymt_Cataogs规格表
        List<Map<String,Object>> catalogs = ipm.selectCatalogsByProdId(productId);
        for(int i=0;i<catalogs.size();i++){
            if(prodSaveModel.getCatalogList().get(0).getPrice()==Double.valueOf(catalogs.get(i).get("fQuotePrice").toString())){
                Logger.verifyEquals(addpro.getSellerId(),Integer.parseInt(catalogs.get(i).get("iUserId").toString()),"验证sellerid");
                Logger.verifyEquals(prodSaveModel.getCatalogList().get(i).getPrice(),Double.valueOf(catalogs.get(i).get("fQuotePrice").toString()),"验证原价");
                Logger.verifyEquals(prodSaveModel.getCatalogList().get(i).getNewPrice(),Double.valueOf(catalogs.get(i).get("fNewCustomerPrice").toString()),"验证新客价");
                Logger.verifyEquals(prodSaveModel.getCatalogList().get(i).getVipPrice(),Double.valueOf(catalogs.get(i).get("fVipPrice").toString()),"验证vip价");
                if(addpro.getProduct().getCatalogList().get(i).getMarketPrice()!= 0){
                    Logger.verifyEquals(prodSaveModel.getCatalogList().get(i).getMarketPrice(),Double.valueOf(catalogs.get(i).get("fMarketPrice").toString()),"验证市场价");
                }
                Logger.verifyEquals(prodSaveModel.getCatalogList().get(i).getAction(),Integer.parseInt(catalogs.get(i).get("iAction").toString()),"验证规格状态");
                Logger.verifyEquals(prodSaveModel.getCatalogList().get(i).getStock(),Integer.parseInt(catalogs.get(i).get("iNum").toString()),"验证规格库存");
                if(addpro.getProduct().getCatalogList().get(i).getSku()!=null){
                    Logger.verifyEquals(prodSaveModel.getCatalogList().get(i).getSku(),catalogs.get(i).get("sSKU").toString(),"验证SKU编号");
                }
                Logger.verifyEquals(prodSaveModel.getCatalogList().get(i).getMultiLogistics(),Integer.parseInt(catalogs.get(i).get("iMultiLogistics").toString()),"验证是否支持多物流");
                Logger.verifyEquals(prodSaveModel.getCatalogList().get(i).isPreSale(),catalogs.get(i).get("IsPreSale"),"验证是否预定");
                AssertService.assertTime(YMTDateUtil.getDate(),(Date) catalogs.get(i).get("dAddTime"),120,"验证商品规格的发布时间");
            }

            //规格属性
            List<Map<String,Object>> catalogProAndVals = ipm.selectCatalogProAndValByCatalogId(catalogs.get(i).get("sCatalogId").toString());
            for(int j=0;j<prodSaveModel.getCatalogList().get(i).getPropertyList().size();j++){
                Logger.verifyEquals(productId,catalogProAndVals.get(j).get("sProductId").toString(),"验证商品属性");
            }
        }

        //验证Ymt_ProductPicture
        List<Map<String,Object>> pictures = ipm.selectPictureByProdIdAndAction0(productId);
        for(int i=0;i<prodSaveModel.getProductPicList().size();i++){
            Logger.verifyEquals(prodSaveModel.getProductPicList().get(i),pictures.get(i).get("sOriUrl").toString(),"验证商品图片地址");
            Logger.verifyEquals(true,Integer.parseInt(pictures.get(i).get("iAction").toString())>-1,"验证商品图片有效");
            AssertService.assertTime(YMTDateUtil.getDate(),(Date) pictures.get(i).get("dAddTime"),120,"验证商品图片的添加时间");
        }

        //商品文描文字表
        List<Map<String,Object>> words = ipm.selectDescConfigWordByProdIdAndSellerId(productId,addpro.getSellerId());
        Logger.verifyEquals(prodSaveModel.getDescModel().getDescription(),words.get(0).get("WordContent").toString(),"验证商品文描文字");
        Logger.verifyEquals(true,words.get(0).get("Status"),"验证商品文描文字有效");
        AssertService.assertTime(YMTDateUtil.getDate(),(Date) words.get(0).get("CreateTime"),120,"验证商品文描表的创建时间");
        //商品文描图片表
        List<Map<String,Object>> pictureList = ipm.selectDescConfigPictureByProdIdAndSellerId(productId,addpro.getSellerId());
        for (int i=0;i<pictureList.size();i++){
            Logger.verifyEquals(prodSaveModel.getDescModel().getDescPicList().get(i),pictureList.get(i).get("PictureUrl").toString(),"验证商品文描图片");
            Logger.verifyEquals(true,Integer.parseInt(pictureList.get(0).get("iAction").toString())>-1,"验证商品文描图片有效");
            AssertService.assertTime(YMTDateUtil.getDate(),(Date) pictureList.get(0).get("CreateTime"),120,"验证商品文描表的创建时间");
        }

        //商品文描模板
        Map<String,Object> map = ipm.selectDescMapPByProdId(productId).get(0);
        Logger.verifyEquals(prodSaveModel.getDescModel().getSizeTemplateId(),Integer.parseInt(map.get("SizeTemplateId").toString()),"验证尺码表编号");
        Logger.verifyEquals(prodSaveModel.getDescModel().getBuyerNoticeId(),Integer.parseInt(map.get("BuyerNoticeId").toString()),"验证买家须知编号");
        Logger.verifyEquals(prodSaveModel.getDescModel().getSellerServiceId(),Integer.parseInt(map.get("SellerServiceId").toString()),"验证买手介绍编号");
//        Logger.verifyEquals(prodSaveModel.getDescModel().getDescription(),Integer.parseInt(map.get("declarationId").toString()),"验证报关信息编号");
        AssertService.assertTime(YMTDateUtil.getDate(),(Date)map.get("AddTime"),120,"验证商品文描模板创建时间");

        //商品的视频
        if(addpro.getProduct().getVideoModel()!=null){
            List<Map<String,Object>> videos = ipm.selectProdVideoByProdId(productId,addpro.getSellerId());
            for(int i=0;i<videos.size();i++){
                Logger.verifyEquals(addpro.getSellerId(),Integer.parseInt(videos.get(i).get("SellerId").toString()),"验证商品视频是买手发布");
                Logger.verifyEquals(true,Integer.parseInt(videos.get(i).get("Action").toString())>-1,"验证商品视频有效");
                AssertService.assertTime(YMTDateUtil.getDate(),(Date)videos.get(i).get("AddTime"),120,"验证商品视频创建时间");
            }
        }

        //商品运费模板
        if(addpro.getProduct().getFreightTemplateList() != null){
            for(int i=0;i<addpro.getProduct().getFreightTemplateList().size();i++){
                List<Map<String,Object>> deliv = ipm.selectDeliveryTplByProductIdAndTplId(productId,addpro.getProduct().getFreightTemplateList().get(i).getTemplateId());
                Logger.verifyEquals(addpro.getProduct().getFreightTemplateList().get(i).getCatalogStatus(),Integer.parseInt(deliv.get(i).get("CatalogStatus").toString()),"验证配送方式");
                Logger.verifyEquals(productId,deliv.get(i).get("ProductId").toString(),"验证商品id");
                AssertService.assertTime(YMTDateUtil.getDate(),(Date)deliv.get(i).get("AddTime"),120,"验证商品模板表数据创建时间");
            }
        }

        if (addpro.getProduct().getLiveRoomId()!=0){
            LiveRoomWapper liveRoomWapper = new LiveRoomWapper();
            List<Map> listm = liveRoomWapper.selectLiveproductByIdAndPid(addpro.getProduct().getLiveRoomId(), productId);
            Logger.verifyEquals(1, listm.size(), "验证商品记录加入到数据库");
            Map pinfo = listm.get(0);
            Logger.verifyEquals(addpro.getSellerId(), pinfo.get("UserId"), "验证用户id");
            // 加入默认可售
            Logger.verifyEquals(1, pinfo.get("Status"), "验证Status");
            // 加入默认非置顶
            Logger.verifyEquals(false, pinfo.get("IsTop"), "验证IsTop");
            //默认false
            Logger.verifyEquals(false, pinfo.get("linkword"), "验证linkword");
            LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(addpro.getProduct().getLiveRoomId());
        }

        //发送同步指令SyncActivityProduct
        MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
        List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
        if(joa.size()==0){
            Thread.sleep(5000);
            joa = MqQueryCallService.GetMqMessage(MessageListBean);
        }
        joa.forEach(ele->{
            Logger.debug(ele.toString());
        });
    }

    public static ModifySellerProductRequest getModifySellerProductRequestFromAddProductBean(String productId,AddSellerProductRequest addBean){
        IntergratedProductMapper ipm = SqlMapperFactory.getIntergratedProductMapper();

        ModifySellerProductRequest modifyBean = new ModifySellerProductRequest();
        modifyBean.setFirstRelease(addBean.isFirstRelease());
        modifyBean.setProduct(addBean.getProduct());
        modifyBean.setSellerId(addBean.getSellerId());
        modifyBean.setProductId(productId);
        modifyBean.setProductSite(addBean.getProductSite());
        modifyBean.setSellerName(addBean.getSellerName());
        modifyBean.getProduct().setProductId(productId);
        modifyBean.getProduct().setReleaseProduct(false);

        List<CatalogSaveModel> catalogListReq = modifyBean.getProduct().getCatalogList();
        List<CatalogSaveModel> catalogSaveModelInSql = new ArrayList<>();


        List<Map<String,Object>> catalogsInSqlMap = ipm.selectCatalogsByProdId(productId);
        for(Map<String,Object> catalogMap : catalogsInSqlMap){
            CatalogSaveModel catalogSaveModel = new CatalogSaveModel();
            catalogSaveModel.setCatalogId(catalogMap.get("sCatalogId").toString());

            //属性
            List<CatalogPropertySaveModel> propertyList = new ArrayList<>();
            List<Map<String,Object>> proAndValMapList = ipm.selectCatalogProAndValByCatalogId(catalogMap.get("sCatalogId").toString());

            for(Map<String,Object> proAndValMap: proAndValMapList){
                CatalogPropertySaveModel catalogPropertySaveModel = new CatalogPropertySaveModel();
                catalogPropertySaveModel.setPropertyName(proAndValMap.get("sProductProperty").toString());
                catalogPropertySaveModel.setPropertyValue(proAndValMap.get("sCategoryAttribute").toString());
                catalogPropertySaveModel.setPropertyUrl((proAndValMap.get("sPicUrl") == null) ? null : proAndValMap.get("sPicUrl").toString());
                propertyList.add(catalogPropertySaveModel);
            }

            catalogSaveModel.setPropertyList(propertyList);
            catalogSaveModelInSql.add(catalogSaveModel);
        }


        //找到对应匹配请求的规格 设置catalog值
        List<String> catalogIds = catalogsInSqlMap.stream().map(x->x.get("sCatalogId").toString()).collect(Collectors.toList());

        if (catalogListReq.size()==1){
            //单规格
            catalogListReq.get(0).setCatalogId(catalogIds.get(0));
        }else{
            //多规格
            for (CatalogSaveModel catalogSaveModelReq:catalogListReq){
                if (catalogSaveModelReq.getPropertyList().size()==1){
                    //单属性
                    String property  = catalogSaveModelReq.getPropertyList().get(0).getPropertyValue();
                    CatalogSaveModel sqlCatalog = catalogSaveModelInSql.stream()
                            .filter(x->x.getPropertyList().get(0).getPropertyValue().equals(property))
                            .findFirst().orElse(null);
//					Logger.verifyIsNull(sqlCatalog, "该属性应该存在规格:["+property+"]");
                    catalogSaveModelReq.setCatalogId(sqlCatalog.getCatalogId());

                }else{
                    //双属性
                    String property1 = catalogSaveModelReq.getPropertyList().get(0).getPropertyValue();
                    String property2 = catalogSaveModelReq.getPropertyList().get(1).getPropertyValue();
                    CatalogSaveModel sqlCatalog = catalogSaveModelInSql.stream()
                            .filter(x->(x.getPropertyList().get(0).getPropertyValue().equals(property1) && x.getPropertyList().get(1).getPropertyValue().equals(property2))
                                    ||(x.getPropertyList().get(1).getPropertyValue().equals(property1) && x.getPropertyList().get(0).getPropertyValue().equals(property2)))
                            .findFirst().orElse(null);

//					Logger.verifyNotNull(sqlCatalog, "该属性应该存在规格:["+property1+","+property2+"]");
                    catalogSaveModelReq.setCatalogId(sqlCatalog.getCatalogId());
                    catalogSaveModelReq.setOperateType(2);
                }
            }
        }

        return modifyBean;
    }

    public static void checkModifyProduct(String productId, ModifySellerProductRequest addpro) throws Exception {
        //验证Ymt_Products商品信息
        Map pmap = ipm.selectProductByProdId(productId);
        Logger.verifyEquals(addpro.getSellerId(),Integer.parseInt(pmap.get("iUserId").toString()),"验证SellerId");
        Logger.verifyEquals(addpro.getSellerName(), pmap.get("SellerLoginId").toString(), "验证sellerName");
        ProductSaveModel prodSaveModel = addpro.getProduct();
        Logger.verifyEquals(prodSaveModel.getProductName(),pmap.get("sProduct").toString(),"验证productName");
        Logger.verifyEquals(prodSaveModel.getSpuId(),Integer.parseInt(pmap.get("iSpuId").toString()),"验证spuid");
        Logger.verifyEquals(prodSaveModel.getSecondCategoryId(),Integer.parseInt(pmap.get("iCategoryId").toString()),"验证二级类目编号");
        Logger.verifyEquals(prodSaveModel.getBrandId(),Integer.parseInt(pmap.get("iBrandId").toString()),"验证品牌编号");

        AssertService.assertTime(YMTDateUtil.getDate(), (Date)pmap.get("dAddTime"), 120,"验证商品发布时间");
        AssertService.assertTime(YMTDateUtil.getDate(), (Date)pmap.get("dLastUpdate"), 120,"验证商品最后更新时间");

        Logger.verifyEquals(prodSaveModel.getProductPicList().get(0),pmap.get("sPicUrl").toString(),"验证商品主图（首图）");
        Logger.verifyEquals(0,Integer.parseInt(pmap.get("iAction").toString()),"验证action");
        Logger.verifyEquals(prodSaveModel.isAutoRefresh(),pmap.get("bAutoRefresh"),"验证商品是否自动延期");
        Logger.verifyEquals(prodSaveModel.getCatalogType(),Integer.parseInt(pmap.get("iCatalogType").toString()),"验证商品备货方式");
        Logger.verifyEquals(prodSaveModel.getCatalogStatus(),Integer.parseInt(pmap.get("iCatalogStatus").toString()),"验证商品物流类型");
        Logger.verifyEquals(prodSaveModel.getThirdCategoryId(),Integer.parseInt(pmap.get("iThirdCategoryId").toString()),"验证商品三级类目编号");
        Logger.verifyEquals(prodSaveModel.getTariffType(),Integer.parseInt(pmap.get("iTariffType").toString()),"验证商品交税方式");
        Logger.verifyEquals(prodSaveModel.isNoticeRisk(),pmap.get("bNoticeRisk"),"验证商品砍单风险");
        Logger.verifyEquals(false,pmap.get("isNew"),"验证是否新品");
        Logger.verifyEquals(prodSaveModel.getBondedArea(),Integer.parseInt(pmap.get("iBondedArea").toString()),"验证商品保税区");
        Logger.verifyEquals(prodSaveModel.getMultiLogistics(),Integer.parseInt(pmap.get("iMultiLogistics").toString()),"验证多物流类型");
        Logger.verifyEquals(prodSaveModel.getFlightBalance(),Double.valueOf(pmap.get("dFlightBalance").toString()),"验证多物流差价");
        Logger.verifyEquals(prodSaveModel.getWeightUnit(),Integer.parseInt(pmap.get("WeightUnit").toString()),"验证多商品重量");
        Logger.verifyEquals(prodSaveModel.getProductType(),Integer.parseInt(pmap.get("ProductType").toString()),"验证商品类型");
        Logger.verifyEquals(prodSaveModel.getProductCode(),pmap.get("sProductCode").toString(),"验证商品备案号");
        Logger.verifyEquals(prodSaveModel.getRemark(),pmap.get("Remark").toString(),"验证商品描述");
        Logger.verifyEquals(prodSaveModel.getPackageDeliveryType(),Integer.parseInt(pmap.get("PackageDeliveryType").toString()),"验证商品描述");

        Date reqStartDate = YMTDateUtil.getDate(addpro
                .getProduct().getValidStart(), YMTDateUtil.YMDHMS);
        Date reqEndDate = YMTDateUtil.getDate(addpro
                .getProduct().getValidEnd(), YMTDateUtil.YMDHMS);
        Date startDateInSql = (Date) pmap.get("validStart");
        Date endDateInSql = (Date) pmap.get("validEnd");

        //验证商品开始的有效期
        AssertService.assertTime(reqStartDate, startDateInSql, 120,"验证validstart");
        //验证商品结束的有效期
        AssertService.assertTime(reqEndDate, endDateInSql, 120,"验证validend");
        //验证商品的发布时间
        AssertService.assertTime(YMTDateUtil.getDate(),(Date) pmap.get("dAddTime"),120,"验证商品的发布时间");

        for (CatalogSaveModel catalogSaveModel :addpro.getProduct().getCatalogList()) {
            //规格表
            Map<String,Object> map = ipm.selectCatalogsByCatalogId(catalogSaveModel.getCatalogId());
            Logger.verifyEquals(productId,map.get("sProductId").toString(),"验证productId");
            Logger.verifyEquals(addpro.getSellerId(),Integer.parseInt(map.get("iUserId").toString()),"验证sellerId");
            Logger.verifyEquals(catalogSaveModel.getPrice(),Double.valueOf(map.get("fQuotePrice").toString()),"验证原价");
            Logger.verifyEquals(catalogSaveModel.getNewPrice(),Double.valueOf(map.get("fNewCustomerPrice").toString()),"验证新客价");
            Logger.verifyEquals(catalogSaveModel.getVipPrice(),Double.valueOf(map.get("fVipPrice").toString()),"验证vip价");
//            Logger.verifyEquals(catalogSaveModel.getfMarketPrice(),Double.valueOf(map.get("fMarketPrice").toString()),"验证市场价");
            Logger.verifyEquals(0,Integer.valueOf(map.get("iAction").toString()),"验证action");
            Logger.verifyEquals(catalogSaveModel.getStock(),Integer.parseInt(map.get("iNum").toString()),"验证库存");
            Logger.verifyEquals(catalogSaveModel.isPreSale(),map.get("IsPreSale"),"验证是否预定");
            Logger.verifyEquals(catalogSaveModel.isPackage(),map.get("IsPackage"),"验证是否套装");
            Logger.verifyEquals(catalogSaveModel.getMultiLogistics(),Integer.parseInt(map.get("iMultiLogistics").toString()),"验证是否支持多物流");
            if(catalogSaveModel.getSku()!=null){
                Logger.verifyEquals(catalogSaveModel.getSku(),map.get("sSKU").toString(),"验证sku");
            }
            if(catalogSaveModel.getProductCode()!=null){
                Logger.verifyEquals(catalogSaveModel.getSku(),map.get("sProductCode").toString(),"验证商品条码");
            }
            AssertService.assertTime(YMTDateUtil.getDate(),(Date) map.get("UpdateTime"),120,"验证商品规格的更新时间");

            //规格属性表
            List<Map<String,Object>> maps = ipm.selectCatalogProAndValByCatalogId(catalogSaveModel.getCatalogId());
            Logger.debug(maps);
            List<CatalogPropertySaveModel> catalogPropertySaveModels = catalogSaveModel.getPropertyList();
            for (Map<String,Object> property:maps) {
                Logger.verifyEquals(productId,property.get("sProductId").toString(),"验证规格属性表中的productId");
            }
        }

        //验证Ymt_ProductPicture
        List<Map<String,Object>> pictures = ipm.selectPictureByProdIdAndAction0(productId);
        for(int i=0;i<prodSaveModel.getProductPicList().size();i++){
            Logger.verifyEquals(prodSaveModel.getProductPicList().get(i),pictures.get(i).get("sOriUrl").toString(),"验证商品图片地址");
            Logger.verifyEquals(true,Integer.parseInt(pictures.get(i).get("iAction").toString())>-1,"验证商品图片有效");
            AssertService.assertTime(YMTDateUtil.getDate(),(Date) pictures.get(i).get("dAddTime"),120,"验证商品图片的添加时间");
        }

        //商品文描文字表
        List<Map<String,Object>> words = ipm.selectDescConfigWordByProdIdAndSellerId(productId,addpro.getSellerId());
        Logger.verifyEquals(prodSaveModel.getDescModel().getDescription(),words.get(0).get("WordContent").toString(),"验证商品文描文字");
        Logger.debug(words.get(0).get("Status").toString());
        Logger.verifyEquals(true,words.get(0).get("Status"),"验证商品文描文字有效");
        AssertService.assertTime(YMTDateUtil.getDate(),(Date) words.get(0).get("CreateTime"),120,"验证商品文描表的创建时间");
        //商品文描图片表
        List<Map<String,Object>> pictureList = ipm.selectDescConfigPictureByProdIdAndSellerId(productId,addpro.getSellerId());
        for (int i=0;i<pictureList.size();i++){
            Logger.verifyEquals(prodSaveModel.getDescModel().getDescPicList().get(i),pictureList.get(i).get("PictureUrl").toString(),"验证商品文描图片");
            Logger.verifyEquals(true,Integer.parseInt(pictureList.get(0).get("iAction").toString())>-1,"验证商品文描图片有效");
            AssertService.assertTime(YMTDateUtil.getDate(),(Date) pictureList.get(0).get("CreateTime"),120,"验证商品文描表的创建时间");
        }

        //商品文描模板
        Map<String,Object> map = ipm.selectDescMapPByProdId(productId).get(0);
        Logger.verifyEquals(prodSaveModel.getDescModel().getSizeTemplateId(),Integer.parseInt(map.get("SizeTemplateId").toString()),"验证尺码表编号");
        Logger.verifyEquals(prodSaveModel.getDescModel().getBuyerNoticeId(),Integer.parseInt(map.get("BuyerNoticeId").toString()),"验证买家须知编号");
        Logger.verifyEquals(prodSaveModel.getDescModel().getSellerServiceId(),Integer.parseInt(map.get("SellerServiceId").toString()),"验证买手介绍编号");
//        Logger.verifyEquals(prodSaveModel.getDescModel().getDescription(),Integer.parseInt(map.get("declarationId").toString()),"验证报关信息编号");
        AssertService.assertTime(YMTDateUtil.getDate(),(Date)map.get("AddTime"),120,"验证商品文描模板创建时间");

        //商品的视频
        if(addpro.getProduct().getVideoModel()!=null){
            List<Map<String,Object>> videos = ipm.selectProdVideoByProdId(productId,addpro.getSellerId());
            for(int i=0;i<videos.size();i++){
                Logger.verifyEquals(addpro.getSellerId(),Integer.parseInt(videos.get(i).get("SellerId").toString()),"验证商品视频是买手发布");
                Logger.verifyEquals(true,Integer.parseInt(videos.get(i).get("Action").toString())>-1,"验证商品视频有效");
                AssertService.assertTime(YMTDateUtil.getDate(),(Date)videos.get(i).get("AddTime"),120,"验证商品视频创建时间");
            }
        }

        //商品运费模板
        if(addpro.getProduct().getFreightTemplateList() != null){
            for(int i=0;i<addpro.getProduct().getFreightTemplateList().size();i++){
                List<Map<String,Object>> deliv = ipm.selectDeliveryTplByProductIdAndTplId(productId,addpro.getProduct().getFreightTemplateList().get(i).getTemplateId());
                Logger.verifyEquals(addpro.getProduct().getFreightTemplateList().get(i).getCatalogStatus(),Integer.parseInt(deliv.get(i).get("CatalogStatus").toString()),"验证配送方式");
                Logger.verifyEquals(productId,deliv.get(i).get("ProductId").toString(),"验证商品id");
                AssertService.assertTime(YMTDateUtil.getDate(),(Date)deliv.get(i).get("AddTime"),120,"验证商品模板表数据创建时间");
            }
        }
        //发送同步指令SyncActivityProduct
        MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
        List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
        if(joa.size()==0){
            Thread.sleep(5000);
            joa = MqQueryCallService.GetMqMessage(MessageListBean);
        }
        joa.forEach(ele->{
            Logger.debug(ele.toString());
        });
    }

    public static void checkAddMicroProduct(String productId, AddMicroProductBean microProductBean) throws IOException, InterruptedException {
        Map pmap = ipm.selectProductByProdId(productId);
        Logger.debug(pmap);
        //商品表数据验证
        WeChatProductModel productModel = microProductBean.getProduct();
        Logger.verifyEquals(productModel.getSellerId(),Integer.parseInt(pmap.get("iUserId").toString()),"验证买手id");
        Logger.verifyEquals(productModel.getSecondCategoryId(),Integer.parseInt(pmap.get("iCategoryId").toString()),"验证二级类目编号");
        Logger.verifyEquals(productModel.getProductName(),pmap.get("sProduct").toString(),"验证商品名称");
        Logger.verifyEquals(productModel.getPicUrls().get(0),pmap.get("sPicUrl").toString(),"验证商品图片");
        Logger.verifyEquals(productModel.getCatalogStatus(),Integer.parseInt(pmap.get("iCatalogStatus").toString()),"验证商品物流类型");
        Logger.verifyEquals(1,Integer.parseInt(pmap.get("ProductType").toString()),"验证商品是微店商品");
        AssertService.assertTime(YMTDateUtil.getDate(),(Date) pmap.get("dAddTime"),120,"验证商品表数据的创建时间");

        //商品文描文字表
        List<Map<String,Object>> words = ipm.selectDescConfigWordByProdIdAndSellerId(productId,productModel.getSellerId());
        Logger.verifyEquals(productModel.getProductDescModel().getDescription(),words.get(0).get("WordContent").toString(),"验证商品文描文字");
        Logger.verifyEquals(true,words.get(0).get("Status"),"验证商品文描文字有效");
        AssertService.assertTime(YMTDateUtil.getDate(),(Date) words.get(0).get("CreateTime"),120,"验证商品文描表的创建时间");
        //商品文描图片表
        List<Map<String,Object>> pictureList = ipm.selectDescConfigPictureByProdIdAndSellerId(productId,productModel.getSellerId());
        for (int i=0;i<pictureList.size();i++){
            Logger.verifyEquals(productModel.getProductDescModel().getDescPicList().get(i),pictureList.get(i).get("PictureUrl").toString(),"验证商品文描图片");
            Logger.verifyEquals(true,Integer.parseInt(pictureList.get(0).get("iAction").toString())>-1,"验证商品文描图片有效");
            AssertService.assertTime(YMTDateUtil.getDate(),(Date) pictureList.get(0).get("CreateTime"),120,"验证商品文描表的创建时间");
        }

        //验证Ymt_ProductPicture
        List<Map<String,Object>> pictures = ipm.selectPictureByProdIdAndAction0(productId);
        for(int i=0;i<productModel.getPicUrls().size();i++){
            Logger.verifyEquals(productModel.getPicUrls().get(i),pictures.get(i).get("sOriUrl").toString(),"验证商品图片地址");
            Logger.verifyEquals(true,Integer.parseInt(pictures.get(i).get("iAction").toString())>-1,"验证商品图片有效");
            AssertService.assertTime(YMTDateUtil.getDate(),(Date) pictures.get(i).get("dAddTime"),120,"验证商品图片的添加时间");
        }

        //商品规格表
        List<Map<String,Object>> maps = ipm.selectCatalogsByProdId(productId);
        for(int i=0;i<maps.size();i++){
            Logger.verifyEquals(productId,maps.get(i).get("sProductId").toString(),"验证规格对应的商品id是发布的商品id");
            AssertService.assertTime(YMTDateUtil.getDate(),(Date) maps.get(i).get("dAddTime"),120,"验证商品表数据的创建时间");
        }

        //发送同步指令SyncActivityProduct
        MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
        List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
        if(joa.size()==0){
            Thread.sleep(5000);
            joa = MqQueryCallService.GetMqMessage(MessageListBean);
        }
        joa.forEach(ele->{
            Logger.debug(ele.toString());
        });
    }

    public static void checkMicroProduct(String productId, MicroProductBean microProductBean) throws IOException, InterruptedException {
        Map pmap = ipm.selectProductByProdId(productId);
        Logger.debug(pmap);
        //商品表数据验证
        WeChatProductModel productModel = microProductBean.getProduct();
        Logger.verifyEquals(productModel.getSellerId(),Integer.parseInt(pmap.get("iUserId").toString()),"验证买手id");
        Logger.verifyEquals(productModel.getSecondCategoryId(),Integer.parseInt(pmap.get("iCategoryId").toString()),"验证二级类目编号");
        Logger.verifyEquals(productModel.getProductName(),pmap.get("sProduct").toString(),"验证商品名称");
        Logger.verifyEquals(productModel.getPicUrls().get(0),pmap.get("sPicUrl").toString(),"验证商品图片");
        Logger.verifyEquals(productModel.getCatalogStatus(),Integer.parseInt(pmap.get("iCatalogStatus").toString()),"验证商品物流类型");
        Logger.verifyEquals(1,Integer.parseInt(pmap.get("ProductType").toString()),"验证商品是微店商品");
        AssertService.assertTime(YMTDateUtil.getDate(),(Date) pmap.get("dAddTime"),120,"验证商品表数据的创建时间");

        //商品文描文字表
        List<Map<String,Object>> words = ipm.selectDescConfigWordByProdIdAndSellerId(productId,productModel.getSellerId());
        Logger.verifyEquals(productModel.getProductDescModel().getDescription(),words.get(0).get("WordContent").toString(),"验证商品文描文字");
        Logger.verifyEquals(true,words.get(0).get("Status"),"验证商品文描文字有效");
        AssertService.assertTime(YMTDateUtil.getDate(),(Date) words.get(0).get("CreateTime"),120,"验证商品文描表的创建时间");
        //商品文描图片表
        List<Map<String,Object>> pictureList = ipm.selectDescConfigPictureByProdIdAndSellerId(productId,productModel.getSellerId());
        for (int i=0;i<pictureList.size();i++){
            Logger.verifyEquals(productModel.getProductDescModel().getDescPicList().get(i),pictureList.get(i).get("PictureUrl").toString(),"验证商品文描图片");
            Logger.verifyEquals(true,Integer.parseInt(pictureList.get(0).get("iAction").toString())>-1,"验证商品文描图片有效");
            AssertService.assertTime(YMTDateUtil.getDate(),(Date) pictureList.get(0).get("CreateTime"),120,"验证商品文描表的创建时间");
        }

        //验证Ymt_ProductPicture
        List<Map<String,Object>> pictures = ipm.selectPictureByProdIdAndAction0(productId);
        for(int i=0;i<productModel.getPicUrls().size();i++){
            Logger.verifyEquals(productModel.getPicUrls().get(i),pictures.get(i).get("sOriUrl").toString(),"验证商品图片地址");
            Logger.verifyEquals(true,Integer.parseInt(pictures.get(i).get("iAction").toString())>-1,"验证商品图片有效");
            AssertService.assertTime(YMTDateUtil.getDate(),(Date) pictures.get(i).get("dAddTime"),120,"验证商品图片的添加时间");
        }

        //商品规格表
        List<Map<String,Object>> maps = ipm.selectCatalogsByProdId(productId);
        for(int i=0;i<maps.size();i++){
            Logger.verifyEquals(productId,maps.get(i).get("sProductId").toString(),"验证规格对应的商品id是发布的商品id");
            AssertService.assertTime(YMTDateUtil.getDate(),(Date) maps.get(i).get("dAddTime"),120,"验证商品表数据的创建时间");
        }
        //发送同步指令SyncActivityProduct
        MessageListBean MessageListBean = MqQueryCallService.initPMongoCrud(productId);
        List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
        if(joa.size()==0){
            Thread.sleep(5000);
            joa = MqQueryCallService.GetMqMessage(MessageListBean);
        }
        joa.forEach(ele->{
            Logger.debug(ele.toString());
        });
    }
}
